package br.com.vti.sisp_sicrim.antigo.controller.relatorios;

import java.io.FileNotFoundException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import net.sf.jasperreports.engine.JRException;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.interceptor.download.InputStreamDownload;
import br.com.vti.sisp_sicrim.antigo.model.DidCadastro;
import br.com.vti.sisp_sicrim.antigo.model.Idclc001;
import br.com.vti.sisp_sicrim.antigo.model.SicControle;
import br.com.vti.sisp_sicrim.antigo.model.Sisldat8;
import br.com.vti.sisp_sicrim.antigo.model.Sisll001;
import br.com.vti.sisp_sicrim.antigo.model.Tablele;
import br.com.vti.sisp_sicrim.antigo.util.Relatorios;
import br.com.vti.sisp_sicrim.antigo.util.Sessao;

/**
 * Classe responsavel por encapsular o tratamento e as consistencias da tela Idcpc004Report
 * 
 * @author Incode - Data: mai/2014
 * 
 */
public class Idcpc004Report {
	private String nomeClasse;
	private int datexp;
	private int datatu;
	private int datnas;
	private String nomide;
	private String nommae;
	private String cabecaCet;
	private int ct;
	private String cabecaSeg;
	private String cabecaIde;
	private int dataCorrente;
	private Integer dinideNumpos; // DB
	private Integer dinideMatfun; // DB
	private String dinideRenaid; // DB
	private Long dinideRegger; // DB
	public int datini;
	public int datfim;
	private String nroPagina;
	private String horaCorrente;
	private Result result;
	private Sessao sessao;
	private Relatorios report;
	// Classes views
	DidCadastro vwDidcad = new DidCadastro();
	SicControle vwDvecon = new SicControle();
	// Classes includes
	Idclc001 idclc001 = new Idclc001();
	Sisldat8 sisldat8 = new Sisldat8();
	Sisll001 sisll001 = new Sisll001();
	Tablele tablele = new Tablele();

	public Idcpc004Report() throws JRException, ParseException {
		inicializar();
	}

	public Idcpc004Report(Sessao sessao) throws JRException, ParseException {
		this.sessao = sessao;
		inicializar();
	}

	public void inicializar() throws JRException, ParseException {
		report = new Relatorios();
		nomeClasse = this.getClass().getSimpleName();
		datexp = 0;
		datatu = 0;
		datnas = 0;
		nomide = "";
		nommae = "";
		ct = 0;
		dataCorrente = 0;
		report.setNumeroRel(1, "C");
		{
			report.setNumeroLinhaRel(1, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", " ");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(2, 4);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "*");
				report.adicionaCampo(3, 70, "Cabecacet", "X", "", "");
				report.adicionaCampo(117, 9, "lit_117_9", "C", "", "PAGINA:  ");
				report.adicionaCampo(127, 5, "nroPagina", "S", "ZZZ.Z99", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(3, 3);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "*");
				report.adicionaCampo(3, 60, "Cabecaseg", "X", "", "");
				report.adicionaCampo(117, 16, "lit_117_16", "C", "", "RELAT:  IDCPC004");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(4, 4);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "*");
				report.adicionaCampo(3, 50, "Cabecaide", "X", "", "");
				report.adicionaCampo(117, 5, "lit_117_5", "C", "", "DATA:");
				report.adicionaCampo(123, 8, "dataCorrente", "N", "99/99/9999", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(5, 2);
			{
				report.adicionaCampo(1, 63, "lit_1_63", "C", "", "      RELACAO DAS ATUALIZACOES EFETUADAS PELO POSTO NO CADASTRO");
				report.adicionaCampo(65, 22, "lit_65_22", "C", "", "DE IDENTIFICACAO CIVIL");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(6, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "-");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(7, 9);
			{
				report.adicionaCampo(1, 5, "lit_1_5", "C", "", "POSTO");
				report.adicionaCampo(7, 7, "lit_7_7", "C", "", "MATRIC.");
				report.adicionaCampo(15, 8, "lit_15_8", "C", "", "RENAID  ");
				report.adicionaCampo(24, 9, "lit_24_9", "C", "", "DATA EXP.");
				report.adicionaCampo(35, 10, "lit_35_10", "C", "", "DAT.ATUAL.");
				report.adicionaCampo(46, 11, "lit_46_11", "C", "", "REG. GERAL.");
				report.adicionaCampo(67, 10, "lit_67_10", "C", "", "NASCIMENTO");
				report.adicionaCampo(78, 27, "lit_78_27", "C", "", "NOME DA PESSOA IDENTIFICADA");
				report.adicionaCampo(107, 11, "lit_107_11", "C", "", "NOME DA MAE");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(8, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "-");
				report.setFimLinhaRel();
			}
		}
		report.setNumeroRel(2, "D");
		{
			report.setNumeroLinhaRel(1, 9);
			{
				report.adicionaCampo(1, 3, "Dinidenumpos", "N", "", "");
				report.adicionaCampo(6, 7, "Dinidematfun", "N", "", "");
				report.adicionaCampo(15, 12, "Diniderenaid", "X", "", "");
				report.adicionaCampo(30, 8, "Datexp", "N", "99/99/9999", "");
				report.adicionaCampo(42, 8, "Datatu", "N", "99/99/9999", "");
				report.adicionaCampo(53, 13, "Dinideregger", "N", "ZZZZZ9999999-9", "");
				report.adicionaCampo(69, 8, "Datnas", "N", "99/99/9999", "");
				report.adicionaCampo(81, 27, "Nomide", "X", "", "");
				report.adicionaCampo(110, 20, "Nommae", "X", "", "");
				report.setFimLinhaRel();
			}
		}
		report.setNumeroRel(3, "D");
		{
			report.setNumeroLinhaRel(1, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "-");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(2, 2);
			{
				report.adicionaCampo(1, 22, "lit_1_22", "C", "", "TOTAL DE ATUALIZACOES:");
				report.adicionaCampo(24, 7, "Ct", "N", "Z.ZZZ.ZZ9", "");
				report.setFimLinhaRel();
			}
		}
		cabecaCet = "SECRETARIA DE ESTADO DA SEGURAN�A PUBLICA";
		cabecaSeg = "SECRETARIA DE ESTADO DA SEGURAN�A PUBLICA";
		cabecaIde = "INSTITUTO DE IDENTIFICACAO CIVIL - IIC";
		horaCorrente = new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()); // *TIMX
		setCabecacet(cabecaCet);
		setCabecaseg(cabecaSeg);
		setCabecaide(cabecaIde);
		setHoraCorrente(horaCorrente);
	}

	public boolean validar() {
		return true;
	}

	public String getNomeClasse() {
		return nomeClasse;
	}

	public void setNomeClasse(String nomeClasse) throws ParseException {
		this.nomeClasse = nomeClasse;
		report.adicionaValorReport("Program", nomeClasse);
	}

	public int getDatexp() {
		return datexp;
	}

	public void setDatexp(int datexp) throws ParseException {
		this.datexp = datexp;
		report.adicionaValorReport("Datexp", datexp);
	}

	public int getDatatu() {
		return datatu;
	}

	public void setDatatu(int datatu) throws ParseException {
		this.datatu = datatu;
		report.adicionaValorReport("Datatu", datatu);
	}

	public int getDatnas() {
		return datnas;
	}

	public void setDatnas(int datnas) throws ParseException {
		this.datnas = datnas;
		report.adicionaValorReport("Datnas", datnas);
	}

	public String getNomide() {
		return nomide;
	}

	public void setNomide(String nomide) throws ParseException {
		this.nomide = nomide;
		report.adicionaValorReport("Nomide", nomide);
	}

	public String getNommae() {
		return nommae;
	}

	public void setNommae(String nommae) throws ParseException {
		this.nommae = nommae;
		report.adicionaValorReport("Nommae", nommae);
	}

	public String getCabecacet() {
		return cabecaCet;
	}

	public void setCabecacet(String cabecaCet) throws ParseException {
		this.cabecaCet = cabecaCet;
		report.adicionaValorReport("Cabecacet", cabecaCet);
	}

	public int getCt() {
		return ct;
	}

	public void setCt(int ct) throws ParseException {
		this.ct = ct;
		report.adicionaValorReport("Ct", ct);
	}

	public String getCabecaseg() {
		return cabecaSeg;
	}

	public void setCabecaseg(String cabecaSeg) throws ParseException {
		this.cabecaSeg = cabecaSeg;
		report.adicionaValorReport("Cabecaseg", cabecaSeg);
	}

	public String getCabecaide() {
		return cabecaIde;
	}

	public void setCabecaide(String cabecaIde) throws ParseException {
		this.cabecaIde = cabecaIde;
		report.adicionaValorReport("Cabecaide", cabecaIde);
	}

	public int getDataCorrente() {
		return dataCorrente;
	}

	public void setDataCorrente(int dataCorrente) throws ParseException {
		this.dataCorrente = dataCorrente;
		report.adicionaValorReport("dataCorrente", dataCorrente);
	}

	public String getNroPagina() {
		return nroPagina;
	}

	public void setNroPagina(String nroPagina) throws ParseException {
		this.nroPagina = nroPagina;
		report.adicionaValorReport("nroPagina", nroPagina);
	}

	public String getHoraCorrente() {
		return horaCorrente;
	}

	public void setHoraCorrente(String horaCorrente) throws ParseException {
		this.horaCorrente = horaCorrente;
		report.adicionaValorReport("horaCorrente", horaCorrente);
	}

	public void setPageSize(int pagesize) throws JRException {
		report.setPageSize(pagesize);
	}

	public void setLineSize(int linesize) {
		report.setLineSize(linesize);
	}

	public int getPageSize() {
		return report.getPageSize();
	}

	public int getPageLine() {
		return report.getPageLine();
	}

	public void saltaLinhas(int qtdLinhas) throws ParseException, JRException {
		report.saltaLinhas(qtdLinhas);
	}

	public void gravaRelatorio(int nroRel) throws ParseException, JRException {
		setNroPagina(String.valueOf(report.getPageNumber()));
		report.gravaRelatorio(report, nroRel, false);
	}

	public InputStreamDownload imprimir() throws FileNotFoundException, JRException {
		return report.imprimir();
	}

	public Integer getDinideNumpos() {
		return dinideNumpos;
	}

	public void setDinideNumpos(Integer dinideNumpos) throws ParseException {
		this.dinideNumpos = dinideNumpos;
		report.adicionaValorReport("dinideNumpos", dinideNumpos);
	}

	public Integer getDinideMatfun() {
		return dinideMatfun;
	}

	public void setDinideMatfun(Integer dinideMatfun) throws ParseException {
		this.dinideMatfun = dinideMatfun;
		report.adicionaValorReport("dinideMatfun", dinideMatfun);
	}

	public String getDinideRenaid() {
		return dinideRenaid;
	}

	public void setDinideRenaid(String dinideRenaid) throws ParseException {
		this.dinideRenaid = dinideRenaid;
		report.adicionaValorReport("dinideRenaid", dinideRenaid);
	}

	public Long getDinideRegger() {
		return dinideRegger;
	}

	public void setDinideRegger(Long dinideRegger) throws ParseException {
		this.dinideRegger = dinideRegger;
		report.adicionaValorReport("dinideRegger", dinideRegger);
	}

	public int getDatfim() {
		return datfim;
	}

	public void setDatfim(int datfim) throws ParseException {
		this.datfim = datfim;
		report.adicionaValorReport("Datfim", datfim);
	}

	public int getDatini() {
		return datini;
	}

	public void setDatini(int datini) throws ParseException {
		this.datini = datini;
		report.adicionaValorReport("Datini", datini);
	}

}
